package com.four.dao.impl;

import com.four.dao.IStudentDao;
import com.four.entity.Student;
import com.qf.framwork.base.BaseDao;

/**
 * @author HZM
 * @version 2023/2/23
 */
public class StudentDaoImpl extends BaseDao<Student> implements IStudentDao {

    /**
     * 新增学生数据的方法
     * @param student
     * @return
     */
    @Override
    public int insert(Student student) {
        String sql = "insert into student values(null, ?, ?, ?, ?, ?)";
        return super.insert(sql,
                student.getUsername(),
                student.getPassword(),
                student.getName(),
                student.getAge(),
                student.getSex()
                );
    }

    /**
     * 检测学生数据的方法
     * @param column 列名
     * @param field 字段名
     * @return
     */
    @Override
    public int checkColumn(String column, String field) {
        String sql = "select count(*) from user where " + column + " = ?";
        return super.query(sql, resultSet -> {
            if (resultSet.next()){
                return resultSet.getInt(1);
            }
            return 0;
        }, field);
    }
}
